pub fn bczd_4_1() {
  test1();
  test2();
  test3();
}

/// 总结内存对齐：
/// 以下规则叠加
/// 1.排序1：按照类型占用字节数从大到小排序
/// 2.排序2：按照定义先后顺序排序
/// 3.成员之间不留空隙
/// 4.最后补齐对齐空白

fn test1() {
  println!("test1()");
  struct Align1 {
    a: u8,
    b: u32,
    c: u16,
  }
  let a = Align1 { a: 0, b: 0, c: 0 };
  println!("{:?}", std::mem::size_of::<Align1>());
  println!("{:p}", &a);
  println!("a:{:p}", &a.a);
  println!("b:{:p}", &a.b);
  println!("c:{:p}", &a.c);
}

fn test2() {
  println!("test2()");
  struct A {
    a: u16,
    b: u32,
    c: u64,
    d: u16,
    e: u8,
  }
  let a = A {
    a: 1,
    b: 1,
    c: 1,
    d: 1,
    e: 1,
  };
  println!("{:?}", std::mem::size_of::<A>());
  println!("{:p}", &a);
  println!("a:{:p}", &a.a);
  println!("b:{:p}", &a.b);
  println!("c:{:p}", &a.c);
  println!("d:{:p}", &a.d);
  println!("e:{:p}", &a.e);
}

fn test3() {
  println!("test3()");
  struct A {
    a: u8,
    b: u32,
    c: u16,
    d: u8,
    e: u8,
  }
  let a = A {
    a: 1,
    b: 1,
    c: 1,
    d: 1,
    e: 1,
  };
  println!("{:?}", std::mem::size_of::<A>());
  println!("{:p}", &a);
  println!("a:{:p}", &a.a);
  println!("b:{:p}", &a.b);
  println!("c:{:p}", &a.c);
  println!("d:{:p}", &a.d);
  println!("e:{:p}", &a.e);
}
